/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.DragonPokerServer.Thread.ServerRequest;

import java.util.ArrayList;
import org.Comunicator.Element;
import org.Comunicator.Global;
import org.Comunicator.Message;
import org.DragonPokerServer.Classes.Player;
import org.DragonPokerServer.Thread.ThreadUser;
import org.DragonPokerServer.dbclasses.Room;

/**
 *
 * @author alien
 */
public class PlayersInRoomRequest extends GenericServerRequest {

    @Override
    public void processRequest(Message message, ThreadUser user) {
        System.out.println("SERVER-Rooms");
        int id = (Integer) message.getParameters().get("RoomId");
        Message reply = new Message();
        reply.setAction("PlayersInRoomReply");
        reply.getReceiver().add(user.getUser().getUsername());
        for (Room r : Global.rooms) {
            if (r.getId() == id) {
                for (Player tu : r.getPlayers()) {
                    reply.getParameters().add(new Element("Players", tu.getThreadUser().getUser().getUsername()));
                }
            }
        }
        Global.messages.addMessageToSend(reply);
    }

    @Override
    public boolean isToProcessing(Message message, ThreadUser user) {
        if ("PlayersInRoom".equals(message.getAction()) == true) {
            return true;
        }
        return false;
    }
}
